package aiku.numericalcontroloa.Controller.EmployeeProfileController;

import aiku.numericalcontroloa.Base.Utils.OSSUploaderUtils;
import aiku.numericalcontroloa.Base.Utils.Result;
import aiku.numericalcontroloa.Model.Dto.EmployeeProfileDto;
import aiku.numericalcontroloa.Model.Entity.EmployeeProfile;
import aiku.numericalcontroloa.Model.Vo.EmployeeProfileInfoVo;
import aiku.numericalcontroloa.Model.Vo.EmployeeProfileVo;
import aiku.numericalcontroloa.Service.Impl.EmployeeProfileServiceImpl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author 马文杰
 * @version 1.0
 */
@RestController
@RequestMapping("/employeeProfile")
@Slf4j
public class EmployeeProfileController {
    @Autowired
    private EmployeeProfileServiceImpl employeeProfileService;
    @Autowired
    private OSSUploaderUtils ossUploaderUtils;
    /**
         * @description 新增员工档案信息
     * @param employeeProfile 员工档案信息
     * @return aiku.numericalcontroloa.Model.Entity.EmployeeProfile
     */
    @PostMapping("/addEmployeeProfile")
    public Result addEmployeeProfile(@RequestBody EmployeeProfile employeeProfile) {
        return employeeProfileService.addEmployeeProfile(employeeProfile);
    }

    /**
     * @description 用户申请修改员工档案信息，如果是管理员直接修改
     * @param employeeProfile 员工档案信息
     * @return aiku.numericalcontroloa.Model.Entity.EmployeeProfile
     */
    @PostMapping("/updateEmployeeProfile")
    public Result  updateEmployeeProfile(@RequestBody EmployeeProfile employeeProfile) {
        return employeeProfileService.updateEmployeeProfile(employeeProfile);
    }


    /**
     * @description管理员审核员工档案信息
     * @param   id 员工档案信息id,state 审核状态
     * @return aiku.numericalcontroloa.Model.Entity.EmployeeProfile
     */
    @PostMapping("/updateEmployeeUpdateStatus")
    public Result  updateEmployeeProfileByAdmin(@RequestParam("id")String id,@RequestParam("state") boolean state) {
        //在这里调用service层的方法
        boolean i =  employeeProfileService.updateEmployeeProfileByAdmin(id,state);
        if(i){
            return  Result.success("200","审核成功");
        }
        return Result.success("400","审核失败");
    }

    /**
     * @description 管理员查看所有员工档案分页
     * @param
     * @return aiku.numericalcontroloa.Model.Entity.EmployeeProfile
     */
        @PostMapping("/selectEmployeeProfileByAdmin")
    public Result  selectEmployeeProfileByAdmin(@RequestParam Integer page,Integer size) {
        Page pages = new Page(page, size);
        //在这里调用service层的方法
        EmployeeProfileInfoVo profileList =  employeeProfileService.selectEmployeeProfileByAdmin(pages);
        return Result.success("200",profileList);
    }

    /**
     * @description 上传商品图片
     * @param file
     * @return  com.iku.points.pointsbackstage.utils.R
     */
    @PostMapping("/updateEmployeeImg")
    public Result headImg(@RequestParam("file") MultipartFile file){
        String fileUrl = ossUploaderUtils.uploadFile(file);
        return Result.success("200",fileUrl);
    }

    /**
         * @description 根据员工id查询员工档案信息
     * @param userId  员工id
     * @return aiku.numericalcontroloa.Model.Entity.EmployeeProfile
     */

    @PostMapping("/selectEmployeeProfileById")
    public Result  selectEmployeeProfileById(@RequestParam("userId")String userId) {
        //在这里调用service层的方法
        EmployeeProfileVo profileList =  employeeProfileService.selectEmployeeProfileById(userId);
        return Result.success("200",profileList);
    }

    /**
         * @description 分页查询待审核员工档案信息,审核中，未通过信息
     * @param page 当前页数 size 每页显示条数 type 1待审核 2审核通过 3审核不通过
     * @return aiku.numericalcontroloa.Model.Entity.EmployeeProfile
     */
    @PostMapping("/selectEmployeeProfileByState")
    public Result  selectEmployeeProfileByState(@RequestParam Integer page,Integer size,Integer type) {
        Page pages = new Page(page, size);
        //在这里调用service层的方法
        EmployeeProfileInfoVo profileList =  employeeProfileService.selectEmployeeProfileByState(pages,type);
        return Result.success("200",profileList);
    }

    /**
         * @description 根据员工id删除员工档案信息
     * @param id 编号id
     * @return aiku.numericalcontroloa.Model.Entity.EmployeeProfile
     */
    @PostMapping("/deleteEmployeeProfileById")
    public Result deleteEmployeeProfileById(@RequestParam("id")String id) {
        //在这里调用service层的方法
        boolean i =  employeeProfileService.deleteEmployeeProfileById(id);
        if(i){
            return Result.success("200","删除成功");
        }
        return Result.success("400","删除失败");
    }

    /**
         * @description 通过姓名，手机号，身份证号查询员工档案信息
     * @param name  姓名 phone 手机号 idCard 身份证号
     * @return aiku.numericalcontroloa.Model.Entity.EmployeeProfile
     */
    @PostMapping("/selectEmployeeProfileByName")
    public Result  selectEmployeeProfileByNameOrPhoneOrIdCard(@RequestParam("name")String name) {
        //在这里调用service层的方法
        List<EmployeeProfile> profileList =  employeeProfileService.selectEmployeeProfileByNameOrPhoneOrIdCard(name);
        return Result.success("200",profileList);
    }

    /**
         * @description 根据档案状态模糊搜索员工档案信息
     * @param name 搜索内容，档案状态
     * @return aiku.numericalcontroloa.Model.Entity.EmployeeProfile
     */
    @PostMapping("/selectEmployeeProfileByStateLike")
    public Result  selectEmployeeProfileByStateLike(@RequestParam("name")String name,@RequestParam("type")Integer type) {
        //在这里调用service层的方法
        List<EmployeeProfile> profileList =  employeeProfileService.selectEmployeeProfileByStateLike(name,type);
        return Result.success("200",profileList);
    }

    /**
     * 分页模糊查询
     * 可根据姓名，电话，身份证模糊查询
     * @param employeeProfileDto
     * @return
     */
    @PostMapping("/getEmployeeProfileList")
    public Result getEmployeeProfileList(@RequestBody EmployeeProfileDto employeeProfileDto){
        return employeeProfileService.getEmployeeProfileList(employeeProfileDto);
    }

    /**
     * 根据id获取单个
     * @param employeeProfileDto
     * @return
     */
    @PostMapping("/getEmployeeProfile")
    public Result getEmployeeProfile(@RequestBody EmployeeProfileDto employeeProfileDto){
        return employeeProfileService.getEmployeeProfile(employeeProfileDto);
    }

    /**
     * 根据userId获取缓存
     * @param employeeProfileDto
     * @return
     */
    @PostMapping("/getEmployeeProfileCache")
    public Result getEmployeeProfileCache(@RequestBody EmployeeProfileDto employeeProfileDto){
        return employeeProfileService.getEmployeeProfileCache(employeeProfileDto);
    }

    /**
     * 审核档案
     * @param employeeProfileDto
     * @return
     */
    @PostMapping("/examineProfile")
    public Result examineProfile(@RequestBody EmployeeProfileDto employeeProfileDto){
        return employeeProfileService.examineProfile(employeeProfileDto);
    }

    /**
     * 删除员工档案
     * @param employeeProfileDto
     * @return
     */
    @PostMapping("/deleteEmployeeProfile")
    public Result deleteEmployeeProfile(@RequestBody EmployeeProfileDto employeeProfileDto){
        return employeeProfileService.deleteEmployeeProfile(employeeProfileDto);
    }

    /**
     * 获取档案id列表
     * @return
     */
    @RequestMapping("/getProfileIdList")
    public Result getProfileIdList(){
        return employeeProfileService.getProfileIdList();
    }

}
